using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Adex
{
    /// <summary>
    /// Controller class for PressLog
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class PressLogController
    {
        // Preload our schema..
        PressLog thisSchemaLoad = new PressLog();
        private string userName = string.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}

					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}

				}

				return userName;
            }

        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public PressLogCollection FetchAll()
        {
            PressLogCollection coll = new PressLogCollection();
            Query qry = new Query(PressLog.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public PressLogCollection FetchByID(object PressLogID)
        {
            PressLogCollection coll = new PressLogCollection().Where("PressLogID", PressLogID).Load();
            return coll;
        }

		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public PressLogCollection FetchByQuery(Query qry)
        {
            PressLogCollection coll = new PressLogCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object PressLogID)
        {
            return (PressLog.Delete(PressLogID) == 1);
        }

        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object PressLogID)
        {
            return (PressLog.Destroy(PressLogID) == 1);
        }

        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(byte? CountryID,DateTime? RFDate,int? MediaCode,int? TimeStart,int? TimeEnd,string TimeStartFormatted,string TimeEndFormatted,int? PageNumber,int? PressBodyCode,string Tipology,decimal? RealCost,double? Wide,int? PageType,double? Length,string ClassCode,int? Pages,string Measure,int? ColorCode,int? ProductID,int ProdVersionID,int? CategoryID,int? SubSectorID,int? SectorID,int? BrandID,int? AdvertiserID,int? AgencyID,DateTime DateAdded,DateTime DateModified)
	    {
		    PressLog item = new PressLog();
		    
            item.CountryID = CountryID;
            
            item.RFDate = RFDate;
            
            item.MediaCode = MediaCode;
            
            item.TimeStart = TimeStart;
            
            item.TimeEnd = TimeEnd;
            
            item.TimeStartFormatted = TimeStartFormatted;
            
            item.TimeEndFormatted = TimeEndFormatted;
            
            item.PageNumber = PageNumber;
            
            item.PressBodyCode = PressBodyCode;
            
            item.Tipology = Tipology;
            
            item.RealCost = RealCost;
            
            item.Wide = Wide;
            
            item.PageType = PageType;
            
            item.Length = Length;
            
            item.ClassCode = ClassCode;
            
            item.Pages = Pages;
            
            item.Measure = Measure;
            
            item.ColorCode = ColorCode;
            
            item.ProductID = ProductID;
            
            item.ProdVersionID = ProdVersionID;
            
            item.CategoryID = CategoryID;
            
            item.SubSectorID = SubSectorID;
            
            item.SectorID = SectorID;
            
            item.BrandID = BrandID;
            
            item.AdvertiserID = AdvertiserID;
            
            item.AgencyID = AgencyID;
            
            item.DateAdded = DateAdded;
            
            item.DateModified = DateModified;
            
	    
		    item.Save(UserName);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(int PressLogID,byte? CountryID,DateTime? RFDate,int? MediaCode,int? TimeStart,int? TimeEnd,string TimeStartFormatted,string TimeEndFormatted,int? PageNumber,int? PressBodyCode,string Tipology,decimal? RealCost,double? Wide,int? PageType,double? Length,string ClassCode,int? Pages,string Measure,int? ColorCode,int? ProductID,int ProdVersionID,int? CategoryID,int? SubSectorID,int? SectorID,int? BrandID,int? AdvertiserID,int? AgencyID,DateTime DateAdded,DateTime DateModified)
	    {
		    PressLog item = new PressLog();
		    
				item.PressLogID = PressLogID;
				
				item.CountryID = CountryID;
				
				item.RFDate = RFDate;
				
				item.MediaCode = MediaCode;
				
				item.TimeStart = TimeStart;
				
				item.TimeEnd = TimeEnd;
				
				item.TimeStartFormatted = TimeStartFormatted;
				
				item.TimeEndFormatted = TimeEndFormatted;
				
				item.PageNumber = PageNumber;
				
				item.PressBodyCode = PressBodyCode;
				
				item.Tipology = Tipology;
				
				item.RealCost = RealCost;
				
				item.Wide = Wide;
				
				item.PageType = PageType;
				
				item.Length = Length;
				
				item.ClassCode = ClassCode;
				
				item.Pages = Pages;
				
				item.Measure = Measure;
				
				item.ColorCode = ColorCode;
				
				item.ProductID = ProductID;
				
				item.ProdVersionID = ProdVersionID;
				
				item.CategoryID = CategoryID;
				
				item.SubSectorID = SubSectorID;
				
				item.SectorID = SectorID;
				
				item.BrandID = BrandID;
				
				item.AdvertiserID = AdvertiserID;
				
				item.AgencyID = AgencyID;
				
				item.DateAdded = DateAdded;
				
				item.DateModified = DateModified;
				
		    item.MarkOld();
		    item.Save(UserName);
	    }

    }

}

